//
//  ZDoctorView.m
//  DoctorFAQs
//
//  Created by zjq on 17/2/15.
//  Copyright © 2017年 zjq. All rights reserved.
//

#import "ZDoctorView.h"
#import "ZLabelTools.h"
#import "UIImage+RadiusAndColor.h"
@interface ZDoctorView (){
    UIImageView * _doctorheadView;
    UILabel * _doctorNameLabel;
    UIImageView * _imageview;// 绿色十字标志
    UILabel * _keshiLabel ;
    UILabel * _levalLabel ;
    UILabel * _hospitalLabel;
    UILabel * _timeLabel;
    UIButton * _doctorButton; // 跳转到医生界面的button；
}

@end
@implementation ZDoctorView

- (instancetype)init
{
    self = [super init];
    if (self) {
        [self initlizeInterface];
    }
    return self;
}
- (void)initlizeInterface {
    [self MakeSubView];
    [self addALLSubView];
    [self makeAllSubViewMasnoy];
}
- (void)MakeSubView {
    _doctorheadView = [[UIImageView alloc] init];
    UIImage * image = [UIImage imageNamed:@"about-us"];
    _doctorheadView.image = image;
    _doctorheadView.layer.cornerRadius = 22.5*xsIZE;
    _doctorheadView.layer.masksToBounds = YES;
    
    _doctorheadView.backgroundColor = [UIColor yellowColor];
    _doctorNameLabel = [[UILabel alloc] init];
    [ZLabelTools setThelabel:_doctorNameLabel Textcolor:[UIColor blackColor] backColor:[UIColor clearColor] Fontsize:18 context:@"" isCenter:NO];
    _keshiLabel = [[UILabel alloc] init];
    [ZLabelTools setThelabel:_keshiLabel Textcolor:KHGaryColor666 backColor:[UIColor clearColor] Fontsize:14 context:@"" isCenter:YES];
    _levalLabel = [[UILabel alloc] init];
    [ZLabelTools setThelabel:_levalLabel Textcolor:KHGaryColor666 backColor:[UIColor clearColor] Fontsize:14 context:@"" isCenter:YES];
    _imageview  = [[UIImageView alloc] init];
    _imageview.image = [UIImage imageNamed:@"icon_hospital_green"];
    _hospitalLabel = [[UILabel alloc] init];
    [ZLabelTools setThelabel:_hospitalLabel Textcolor:KHGaryColor666 backColor:[UIColor clearColor] Fontsize:13 context:@"" isCenter:NO];
    _hospitalLabel.textAlignment = NSTextAlignmentLeft;

    _timeLabel = [[UILabel alloc] init];
    [ZLabelTools setThelabel:_timeLabel Textcolor:KHGaryColor backColor:[UIColor clearColor] Fontsize:12 context:@"" isCenter:YES];
    _timeLabel.textAlignment = NSTextAlignmentRight;
    
    _doctorButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [_doctorButton setBackgroundColor:[UIColor clearColor]];
    [_doctorButton addTarget:self action:@selector(DoctorAction:) forControlEvents:UIControlEventTouchUpInside];
}
- (void)addALLSubView {
    [self addSubview:_doctorheadView];
    [self addSubview:_doctorNameLabel];
    [self addSubview:_keshiLabel];
    [self addSubview:_levalLabel];
    [self addSubview:_imageview];
    [self addSubview:_hospitalLabel];
    [self addSubview:_timeLabel];
    [self addSubview:_doctorButton];
}
- (void)makeAllSubViewMasnoy {
    [_doctorheadView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.height.offset(45*xsIZE);
        make.left.equalTo(self).offset(10*xsIZE);
        make.top.equalTo(self).offset(10*ysIZE);
    }];
    
    
    [_doctorNameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_doctorheadView.mas_right).offset(9*xsIZE);
        make.height.offset(18*ysIZE);
        make.width.offset(70*xsIZE);
        make.top.equalTo(self).offset(15*ysIZE);
    }];
    [_imageview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_doctorNameLabel);
        make.width.height.offset(13*ysIZE);
        make.top.equalTo(_doctorNameLabel.mas_bottom).offset(8*ysIZE);
    }];
    [_hospitalLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_doctorNameLabel.mas_bottom).offset(8*ysIZE);
        make.left.equalTo(_imageview.mas_right);
        make.height.offset(13*ysIZE);
        make.width.offset(110*xsIZE);
    }];
    [_timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.mas_right).offset(-10*xsIZE);
        make.height.offset(12*ysIZE);
        make.centerY.equalTo(_hospitalLabel);
        make.width.offset(140*xsIZE);
    }];
    [_keshiLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(_doctorNameLabel);
        make.left.equalTo(_doctorNameLabel.mas_right).offset(5*xsIZE);
        make.height.offset(14*ysIZE);
        make.width.offset(60*xsIZE);
    }];
    [_levalLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(_doctorNameLabel);
        make.left.equalTo(_keshiLabel.mas_right).offset(10*xsIZE);
        make.height.width.equalTo(_keshiLabel);
    }];
    [_doctorButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.width.height.equalTo(self);
    }];
}
-(void)setDModel:(ZDoctorTModel *)dModel {
    _dModel = dModel;
    _doctorNameLabel.text = _dModel.name;
    _keshiLabel.text = _dModel.job_title;
    _levalLabel.text = _dModel.office;
    _hospitalLabel.text = _dModel.hospital;
    _timeLabel.text = _dModel.d_time;
    [_doctorheadView sd_setImageWithURL:[NSURL URLWithString:_dModel.pic] placeholderImage:[UIImage imageNamed:@"about-us"]];
}

- (void)DoctorAction:(UIButton *)sender {
    !self.GoDoctorVCBlock ? : self.GoDoctorVCBlock();
}
@end
